﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Schema;
using Common.Properties;


namespace Common
{
    public class Constants
    {

        private static XmlSchemaSet ACCOUNTING_CUSTOMER_SCHEMA;
        private static XmlSchemaSet ACCOUNTING_ORDER_SCHEMA;

        private static XmlSchemaSet GADGET_INVENTORY_REQUEST_SCHEMA;
        private static XmlSchemaSet GADGET_INVENTORY_RESPONSE_SCHEMA;
        private static XmlSchemaSet GADGET_ITEM_SCHEMA;

        private static XmlSchemaSet WIDGET_INVENTORY_REQUEST_SCHEMA;
        private static XmlSchemaSet WIDGET_INVENTORY_RESPONSE_SCHEMA;
        private static XmlSchemaSet WIDGET_ITEM_SCHEMA;


        public const string QUEUE_URI = "tcp://localhost:61616";

        public const string ACCOUNTING_CUSTOMER_UPDATE_QUEUE = "queue://ACCOUNTING.CUSTOMER";

        public const string WIDGET_INVENTORY_REQUEST_QUEUE = "queue://WIDGET.INVENTORY.REQUEST";
        public const string WIDGET_INVENTORY_RESPONSE_QUEUE = "queue://WIDGET.INVENTORY.RESPONSE";
        public const string WIDGET_CATALOG_QUEUE = "queue://WIDGET.CATALOG";

        public const string GADGET_INVENTORY_REQUEST_QUEUE = "queue://GADGET.INVENTORY.REQUEST";
        public const string GADGET_INVENTORY_RESPONSE_QUEUE = "queue://GADGET.INVENTORY.RESPONSE";
        public const string GADGET_CATALOG_QUEUE = "queue://GADGET.CATALOG";

        public static XmlSchemaSet AccountingCustomerSchema
        {
            get
            {
                if (ACCOUNTING_CUSTOMER_SCHEMA == null)
                {
                    ACCOUNTING_CUSTOMER_SCHEMA = new XmlSchemaSet();
                    ACCOUNTING_CUSTOMER_SCHEMA.Add("http://wgrus.com/Accounting", XmlReader.Create(Open("AccountingCustomer")));
                    ACCOUNTING_CUSTOMER_SCHEMA.Compile();
                }

                return ACCOUNTING_CUSTOMER_SCHEMA;
            }
        }

        public static XmlSchemaSet AccountingOrderSchema
        {
            get
            {
                if (ACCOUNTING_ORDER_SCHEMA == null)
                {
                    ACCOUNTING_ORDER_SCHEMA = new XmlSchemaSet();
                    ACCOUNTING_ORDER_SCHEMA.Add("http://wgrus.com/Accounting", XmlReader.Create(Open("AccountingOrder")));
                    ACCOUNTING_ORDER_SCHEMA.Compile();
                }

                return ACCOUNTING_ORDER_SCHEMA;
            }
        }


        public static XmlSchemaSet GadgetInventoryRequestSchema
        {
            get
            {
                if (GADGET_INVENTORY_REQUEST_SCHEMA == null)
                {
                    GADGET_INVENTORY_REQUEST_SCHEMA = new XmlSchemaSet();
                    GADGET_INVENTORY_REQUEST_SCHEMA.Add("http://gadget.com/WGRUS", XmlReader.Create(Open("GadgetInventoryRequest")));
                    GADGET_INVENTORY_REQUEST_SCHEMA.Compile();
                }

                return GADGET_INVENTORY_REQUEST_SCHEMA;
            }
        }

        public static XmlSchemaSet GadgetInventoryResponseSchema
        {
            get
            {
                if (GADGET_INVENTORY_RESPONSE_SCHEMA == null)
                {
                    GADGET_INVENTORY_RESPONSE_SCHEMA = new XmlSchemaSet();
                    GADGET_INVENTORY_RESPONSE_SCHEMA.Add("http://gadget.com/WGRUS", XmlReader.Create(Open("GadgetInventoryResponse")));
                    GADGET_INVENTORY_RESPONSE_SCHEMA.Compile();
                }

                return GADGET_INVENTORY_RESPONSE_SCHEMA;
            }
        }


        public static XmlSchemaSet GadgetItemSchema
        {
            get
            {
                if (GADGET_ITEM_SCHEMA == null)
                {
                    GADGET_ITEM_SCHEMA = new XmlSchemaSet();
                    GADGET_ITEM_SCHEMA.Add("http://gadget.com/WGRUS", XmlReader.Create(Open("GadgetItem")));
                    GADGET_ITEM_SCHEMA.Compile();
                }

                return GADGET_ITEM_SCHEMA;
            }
        }


        public static XmlSchemaSet WidgetInventoryRequestSchema
        {
            get
            {
                if (WIDGET_INVENTORY_REQUEST_SCHEMA == null)
                {
                    WIDGET_INVENTORY_REQUEST_SCHEMA = new XmlSchemaSet();
                    WIDGET_INVENTORY_REQUEST_SCHEMA.Add("http://widget.com/WGRUS", XmlReader.Create(Open("WidgetInventoryRequest")));
                    WIDGET_INVENTORY_REQUEST_SCHEMA.Compile();
                }

                return WIDGET_INVENTORY_REQUEST_SCHEMA;
            }
        }

        public static XmlSchemaSet WidgetInventoryResponseSchema
        {
            get
            {
                if (WIDGET_INVENTORY_RESPONSE_SCHEMA == null)
                {
                    WIDGET_INVENTORY_RESPONSE_SCHEMA = new XmlSchemaSet();
                    WIDGET_INVENTORY_RESPONSE_SCHEMA.Add("http://widget.com/WGRUS", XmlReader.Create(Open("WidgetInventoryResponse")));
                    WIDGET_INVENTORY_RESPONSE_SCHEMA.Compile();
                }

                return WIDGET_INVENTORY_RESPONSE_SCHEMA;
            }
        }


        public static XmlSchemaSet WidgetItemSchema
        {
            get
            {
                if (WIDGET_ITEM_SCHEMA == null)
                {
                    WIDGET_ITEM_SCHEMA = new XmlSchemaSet();
                    WIDGET_ITEM_SCHEMA.Add("http://widget.com/WGRUS", XmlReader.Create(Open("WidgetItem")));
                    WIDGET_ITEM_SCHEMA.Compile();
                }

                return WIDGET_ITEM_SCHEMA;
            }
        }

        private static StringReader Open(string resourceName)
        {
            var xml = Resources.ResourceManager.GetObject(resourceName);
            var sr = new StringReader(xml.ToString());
            return sr;
        }
    }
}
